package main

/*
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.
*/
/*

Input: 1->2->4, 1->3->4
Output: 1->1->2->3->4->4
*/
type listNode struct {
	val  int
	next *listNode
}

func mergeSortedList(l1 *listNode, l2 *listNode) *listNode {
	if l1 == nil {
		return l2
	}
	if l2 == nil {
		return l1
	}
	//l1,l2 相当于头节点，这个是升序排列，每次挑出一个适合的节点，连接
	if l1.val < l2.val {
		l1.next = mergeSortedList(l1.next, l2)
		return l1
	}
	l2.next = mergeSortedList(l1, l2.next)
	return l2
}
